//package org.ricks.router;
//
//import com.github.benmanes.caffeine.cache.CacheLoader;
//import com.github.benmanes.caffeine.cache.Caffeine;
//import com.github.benmanes.caffeine.cache.LoadingCache;
//import lombok.extern.slf4j.Slf4j;
//import org.checkerframework.checker.nullness.qual.Nullable;
//import org.ricks.ioc.RicksContext;
//import org.ricks.net.rpc.AskPackage;
//import org.ricks.protocol.ProtocolManager;
//
//import java.io.IOException;
//import java.util.Set;
//import java.util.concurrent.BlockingQueue;
//import java.util.concurrent.Executor;
//import java.util.concurrent.Executors;
//import java.util.concurrent.LinkedBlockingQueue;
//
//@Slf4j
//public class TcpServer {
//
//    public volatile static LoadingCache<String, RoleInfo> cache =
//            Caffeine.newBuilder().build(new CacheLoader<String, RoleInfo>() {
//        @Override
//        public @Nullable RoleInfo load(String key) throws Exception {
//            return new RoleInfo();
//        }
//
//    });
//
////    static {
//////        cache = Caffeine.newBuilder().
//////                .maximumSize(50_000)
//////                .removalListener((key, value, cause) -> {
//////                    log.debug("玩家Id:{} 缓存失效 -- 原因:{} ", key, cause);
//////                })
//////                .build(new CacheLoader() {
//////
//////                    @Override
//////                    public @Nullable Object load(Object key) throws Exception {
//////                        return null;
//////                    }
//////
//////                    @Override
//////                    public @Nullable RoleInfo load(String playerId) {
//////
//////                        return new RoleInfo();
//////                    }
//////
//////                });
////    }
//
//    public static void main(String[] args) throws IOException {
//        ProtocolManager.initProtocol(Set.of(InnerMessage.class, AskPackage.class, RpcTestPakcet.class));
//        RicksContext.me().init();
//        NetContext.me().init();
//
//        TcpInnerProtocol innerProtocol = new TcpInnerProtocol();
//        InnerHandler innerHandler = new InnerHandler();
//
//        AioServer tcpServer = new AioServer(9100, innerProtocol, innerHandler);
//        tcpServer.start();
//
////        QueueTask queueTask = new QueueTask();
////
////        QueueTask queueTask1 = new QueueTask();
////
////
////        Thread.ofVirtual().name("ricks1").start(queueTask).start();
////
////        Thread.ofVirtual().name("ricks2").start(queueTask1);
//
////        new Thread(() -> {
////            queueTask.submit(() -> {
////                RoleInfo roleInfo = cache.get("1");
////                roleInfo.setName("ricks1");
////            });
////        }).start();
////
////        new Thread(() -> {
////        queueTask.submit(() -> {
////            RoleInfo roleInfo = cache.get("1");
////            roleInfo.setName("ricks2");
////        });
////        }).start();
////
////        new Thread(() -> {
////        queueTask.submit(() -> {
////            RoleInfo roleInfo = cache.get("1");
////            roleInfo.setName("ricks3");
////        });
////        }).start();
////
//////        new Thread(() -> {
//////            RoleInfo roleInfo = cache.get("1");
//////            roleInfo.setName("ricks1");
//////        }).start();
//////
//////        ThreadUtils.sleep(1);
//////        new Thread(() -> {
//////            RoleInfo roleInfo = cache.get("1");
//////            roleInfo.setName("ricks2");
//////        }).start();
//////
////        for (int i = 0; i < 5; i++) {
////            new Thread(() -> {
////                queueTask.submit(() -> {
////                    RoleInfo roleInfo = cache.get("1");
////                    System.err.println(roleInfo.getName());
////                });
////            }).start();
////        }
//
////
////        for (int i = 0; i < 1 ; i++) {
////            queueTask.submit(() -> {
////                RoleInfo roleInfo = cache.get("1");
////                roleInfo.setName("ricks1");
////            });
////
////            queueTask.submit(() -> {
////                RoleInfo roleInfo = cache.get("1");
////                roleInfo.setName("ricks2");
////            });
////
////            queueTask.submit(() -> {
////                RoleInfo roleInfo = cache.get("1");
////                roleInfo.setName("ricks3");
////
////                queueTask1.submit(() -> {
////                    RoleInfo roleInfo1 = cache.get("1");
////                    System.err.println(roleInfo1.getName());
////                });
////            });
////
////        }
//
//
////        new Thread(() -> {
////            RoleInfo roleInfo = cache.get("1");
////            roleInfo.setName("ricks1");
////        }).start();
////
////        ThreadUtils.sleep(1);
////        new Thread(() -> {
////            RoleInfo roleInfo = cache.get("1");
////            roleInfo.setName("ricks2");
////        }).start();
////
////        for (int i = 0; i < 5; i++) {
////                queueTask.submit(() -> {
////                    RoleInfo roleInfo = cache.get("1");
////                    System.err.println(roleInfo.getName());
////                });
////        }
//
//
//
////        queueTask1.submit(() -> {
////            RoleInfo roleInfo = cache.get("1");
////            roleInfo.setName("ricks4");
////        });
////
////        queueTask1.submit(() -> {
////            RoleInfo roleInfo = cache.get("1");
////            roleInfo.setName("ricks5");
////        });
////
////        queueTask1.submit(() -> {
////            RoleInfo roleInfo = cache.get("1");
////            roleInfo.setName("ricks6");
////        });
////
////        queueTask1.submit(() -> {
////            RoleInfo roleInfo = cache.get("1");
////            System.err.println(roleInfo.getName());
////        });
////        for (int i = 0; i < 5; i++) {
////            queueTask1.submit(() -> {
////                RoleInfo roleInfo = cache.get("1");
////                System.err.println(roleInfo.getName());
////            });
////        }
//    }
//}
//
//
//class QueueTask implements Runnable {
//    private BlockingQueue<Runnable> taks = new LinkedBlockingQueue<>();
//
//    private final Executor executor = Executors.newSingleThreadExecutor();
//
//
//    private volatile boolean starter = true;
//
//    public QueueTask() {
////        executor.execute(this);
//    }
//
//    public void submit (Runnable runnable) {
//        taks.offer(runnable);
////        startTasksIfNeeded();
//    }
//
////    protected void startTasksIfNeeded() {
////        // 只在没有任务正在处理时启动新的执行流程
////        if (running.compareAndSet(false, true)) {
////            executor.execute(() -> {
////                processTasks();
////            });
////        }
////    }
////
////    public void processTasks() {
////        try {
////            while (!taks.isEmpty()) {
////                Runnable nextTask = taks.poll();
////                if (nextTask != null) {
////                    try {
////                        long startTime = System.currentTimeMillis();
////
////                        nextTask.run();
////                    } catch (Exception e) {
////                        e.printStackTrace();
////                    }
////                }
////            }
////        } finally {
////            // 如果在处理任务时有新任务加入，重新检查队列
////            if (!taks.isEmpty()) {
////                startTasksIfNeeded();
////            }
////        }
////
////    }
//
//    @Override
//    public void run() {
//        while (starter) {
//            try {
//                Runnable runnable = taks.take();
//                runnable.run();
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
//        }
//    }
//}
//
//
//class RoleInfo {
//
//    private int sid;
//
//    private String playerId;
//
//    private String name;
//
//    private int lv;
//
//    private int headId;
//
//    private int headFrameId;
//
//    private long combatNum;
//
//    private int curChapterId ;
//
//    private int fightHeroId;
//
//    private long lastLogoutTime;
//
//    public int getSid() {
//        return sid;
//    }
//
//    public void setSid(int sid) {
//        this.sid = sid;
//    }
//
//    public String getPlayerId() {
//        return playerId;
//    }
//
//    public void setPlayerId(String playerId) {
//        this.playerId = playerId;
//    }
//
//    public String getName() {
//        return name;
//    }
//
//    public void setName(String name) {
//        this.name = name;
//    }
//
//    public int getLv() {
//        return lv;
//    }
//
//    public void setLv(int lv) {
//        this.lv = lv;
//    }
//
//    public int getHeadId() {
//        return headId;
//    }
//
//    public void setHeadId(int headId) {
//        this.headId = headId;
//    }
//
//    public int getHeadFrameId() {
//        return headFrameId;
//    }
//
//    public void setHeadFrameId(int headFrameId) {
//        this.headFrameId = headFrameId;
//    }
//
//    public long getCombatNum() {
//        return combatNum;
//    }
//
//    public void setCombatNum(long combatNum) {
//        this.combatNum = combatNum;
//    }
//
//    public int getCurChapterId() {
//        return curChapterId;
//    }
//
//    public void setCurChapterId(int curChapterId) {
//        this.curChapterId = curChapterId;
//    }
//
//    public int getFightHeroId() {
//        return fightHeroId;
//    }
//
//    public void setFightHeroId(int fightHeroId) {
//        this.fightHeroId = fightHeroId;
//    }
//
//    public long getLastLogoutTime() {
//        return lastLogoutTime;
//    }
//
//    public void setLastLogoutTime(long lastLogoutTime) {
//        this.lastLogoutTime = lastLogoutTime;
//    }
//}